/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.support.custom.binding;

/**
 *
 * @author renan_luz
 */
import com.lavantech.gui.comp.DateTimePicker;
import com.lavantech.gui.comp.LocaleSpecificResources;
import java.util.GregorianCalendar;
import org.springframework.richclient.form.binding.Binding;
import org.springframework.binding.form.FormModel;

import javax.swing.*;
import java.util.Map;
import org.springframework.richclient.form.binding.support.AbstractBinder;

public class TimePickerBinder extends AbstractBinder {

    private boolean readOnly = false;

    public TimePickerBinder() {
        super(GregorianCalendar.class);
    }

    public void setReadOnly(boolean readOnly) {
        this.readOnly = readOnly;
    }

    @SuppressWarnings("unchecked")
    protected JComponent createControl(Map context) {
        DateTimePicker timePicker = new DateTimePicker(new GregorianCalendar(), "HH:mm:ss", false, true);
        LocaleSpecificResources.setHourFormat(LocaleSpecificResources.HOUR_FORMAT_24);
        timePicker.getTimePanel().getClockPanel().setHourFormat(LocaleSpecificResources.HOUR_FORMAT_24);
        return timePicker;
    }

    @SuppressWarnings("unchecked")
    protected Binding doBind(JComponent control, FormModel formModel, String formPropertyPath, Map context) {
        return new TimePickerBinding(formModel, formPropertyPath, ((DateTimePicker) control), this.readOnly);
    }
}